home *** CD-ROM | disk | FTP | other *** search
- Path: mail2news.demon.co.uk!genesis.demon.co.uk
- From: Lawrence Kirby <fred@genesis.demon.co.uk>
- Newsgroups: comp.lang.c
- Subject: Re: Pointers to Linked Lists
- Date: Sat, 17 Feb 96 22:59:30 GMT
- Organization: none
- Message-ID: <824597970snz@genesis.demon.co.uk>
- References: <4fjs0b$7sb@texas.nwlink.com>
- Reply-To: fred@genesis.demon.co.uk
- X-NNTP-Posting-Host: genesis.demon.co.uk
- X-Newsreader: Demon Internet Simple News v1.27
- X-Mail2News-Path: genesis.demon.co.uk
-
- In article <4fjs0b$7sb@texas.nwlink.com> jlim@nwlink.com "John Lim" writes:
-
- >please help me with this pointer question
- >
- >
- >typedef struct node
- >{
- > generic_ptr data; (generic_ptr is a pointer to void)
- > struct node *next;
- >} node, *list;
- >
- >so i know that list is a pointer to a node
- >
- >in main i have the lines
- >
- >list pairlist;
- >
- >adtInitializeList (&pair_list) (adtInitializeList is a library
-
- Make that:
-
- adtInitializeList (&pairlist);
-
- >in libadt.c
- >
- >adtInitializeList (list *pL)
- >{
- > *pL=NULL;
- > return OK:
- >}
- >
- >so my questions are:
- >- isn't pL a pointer to a pointer to a node? because it is of type
- >list and list is a pointer to a node
-
- Yes, it is.
-
- >-if so why would one need to use this? why can't you just use
- >adtInitializeList (list pL)?
-
- You can unless adtInitializeList() needs to modify the node pointer i.e.
- pairlist in main() in this case. Function arguments are passed by value
- hence in line with the 2nd version a call of:
-
- adtInitializeList (pairlist);
-
- a copy of the value of pairlist is passed to adtInitializeList() but that
- function can't change the value of pairlist itself.
-
- --
- -----------------------------------------
- Lawrence Kirby | fred@genesis.demon.co.uk
- Wilts, England | 70734.126@compuserve.com
- -----------------------------------------
-